#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    long long maximumSubsequenceCount(string text, string pattern) {
        char prev = pattern[0], next = pattern[1];
        int i = 0, n = text.size();
        long long p_count = 0, n_count = 0, all = 0;
        while (i < n)
        {
            if (text[i] == next)
            {
                n_count++;
                all += p_count;
            }
            if (text[i] == prev) p_count++;
            i++;
        }
        return all += max(n_count, p_count);
    }
};